"""
-------------------------------
- File_Name: responseUtil.py
- Date: 2025/2/15
- Author: yangzhide
- Email: xxzjyzd@126.com
- Description: 统一响应工具类
-------------------------------
"""

from typing import Any

class ResponseUtil:
    """
    查询成功返回data类型
    查询失败返回[]
        资源不存在默认code=404
        其他的异常默认code=500
    """
    @staticmethod
    def success_response(code: int|str = 200, data: Any = None, msg: str = "操作成功") ->Any:
        """成功响应模板"""
        return {
            "code": code,
            "data": data,
            "msg": msg
        }

    @staticmethod
    def success_response_extra(
            total: int =0,
            current: int = 0,
            size: int = 0,
            data: Any = None,
            msg: str = "操作成功"
    ) -> Any:
        """成功响应模板"""
        return {
            "code": 200,
            "data": {
                "records": data,
                "total": total,
                "current": current,
                "size": size
            },
            "msg": msg,
        }

    @staticmethod
    def error_response(code: int | str = 400, msg: str = "操作失败") -> Any:
        """错误响应模板"""
        return {
            "code": code,
            "data": None,
            "msg": msg
        }
